<?php
namespace app\index\controller;

use think\Controller;
use think\Db;

class Index extends Controller
{
    public function index()
    {
        //获取一级分类
        $type = Db::table('type')->where(array('pid'=>0))->select();
        $type2 = array();
        $type3 = array();
        foreach($type as $key=>$value){
            $type[$key]['child']=array();//二级分类的名字
            $type2=Db::table('type')->where("pid=".$value['id'])->select();//获取二级分类

            foreach($type2 as $k=>$v){
                array_push($type[$key]['child'],$v);//合并一级与二级分类
                $type[$key]['child'][$k]['child2']=array();////三级分类的名字
               
                    $type3=Db::table('type')->where("pid=".$v['id'])->select();//获取三级分类
                    foreach($type3 as $v2){


                          array_push($type[$key]['child'][$k]['child2'],$v2);//合并一级二级三级分类
                    }
                  
               
            }

        }
        $this->assign('type',$type);
        //首页轮播图
        $firstcar = Db::table('firstcar') ->where(array('id'=>1))->find();
        //近期特惠
        $recent = Db::table('firstcar') ->where(array('id'=>2))->find();
        //媒体报道
        $media = Db::table('firstcar') ->where(array('id'=>3))->find();
        //蝶变日记
        $butter = Db::table('firstcar') ->where(array('id'=>4))->find();
        $this->assign('firstcar',$firstcar);
        $this->assign('recent',$recent);
        $this->assign('media',$media);
        $this->assign('butter',$butter);
        //医师团队
        $team = Db::table('doctor') ->field('pic')->select();
        $this->assign('team',$team);
        
        return $this->fetch();
    }
}
